import request from '@ey-utils/utils/services/request';
import { transformBaseData } from '@/utils/utils';
import { PagerData } from '@/utils/constants';
import mof from '@/services/common-api/meta-mof'
import api from '../api';
/**
 *
 * @param modelArray 元模型类型
 */
// 获取搜索条件
// 获取 SEARCH,CREATE 调用 isSearch 表示是否是搜索区域的meta
export const getMetaMeta = async (modelArray: string, isSearch?: boolean) => {
  return await request(mof.commonMeta, {
    method: 'get',
    params: {
      modelCode: modelArray,
    },
  }).then(res => {
    if (isSearch) {
      if (res.success) { return res.result }
      return PagerData;
    }
    if (res.success === true) {
      return transformBaseData(res.result);
    }
    return {
      formArrObj: {},
      formArr: [],
    }

  });
};
/**
 *
 * @param url 接口
 * @param modelArray 元模型
 * @param data 额外参数
 */
// 获取 DISPALY,EDIT 调用
export const getMetaMetaData = async (url: string, modelArray: any, data: any = {}, requestMethod?: string) => {
  let obj = {};
  if (requestMethod && requestMethod === 'get') {
    obj = {
      method: 'get',
      params: { queryKeys: { modelArray: Array.isArray(modelArray) ? modelArray : [modelArray] }, ...data }
    }
  } else {
    obj = {
      method: 'post',
      data: { queryKeys: { modelArray: Array.isArray(modelArray) ? modelArray : [modelArray] }, ...data }
    };
  }
  return await request(url, { ...obj }).then(res => {
    if (res.success === true) {
      return transformBaseData(res.result);
    }
    return {
      formArrObj: {},
      formArr: []
    }
  });
};


export const getDicList = async (code: string) => {
  return request(api.dictValueList, {
    params: {
      code
    }
  }).then(res => {
    if (res.success) {
      return res.result
    } else {
      return []
    }
  })
} 
